package cc.telecomdigital.tdstock.activity.groups.foreignexchange;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.ViewFlipper;
import cc.mango.common.FinalKey;
import cc.telecomdigital.tdstock.ColorRefreshTask;
import cc.telecomdigital.tdstock.CommonDefn;
import cc.telecomdigital.tdstock.CustomizeDialog;
import cc.telecomdigital.tdstock.DBHelper;
import cc.telecomdigital.tdstock.DefaultClickHandler;
import cc.telecomdigital.tdstock.ITDLApplication;
import cc.telecomdigital.tdstock.LightStreamerHandlerInterface;
import cc.telecomdigital.tdstock.R;
import cc.telecomdigital.tdstock.RefreshHandlerInterface;
import cc.telecomdigital.tdstock.SystemInfo;
import cc.telecomdigital.tdstock.CommonDefn.DoThingsReturn;
import cc.telecomdigital.tdstock.Framework.UniqueItem.TDStockLog;
import cc.telecomdigital.tdstock.Services.LS_SubscriptionItem;
import cc.telecomdigital.tdstock.Services.LS_UserClient.ILS_UserClient_Response;
import cc.telecomdigital.tdstock.Tools.ActivityGroupController;
import cc.telecomdigital.tdstock.activity.ChangePortraitAndLandscapeActivity;
import cc.telecomdigital.tdstock.activity.chart.ForexChartActivity;
import cc.telecomdigital.tdstock.activity.groups.ForeignExchangeGroup;
import cc.telecomdigital.tdstock.activity.groups.monitor.util.MonitorUtil;
import cc.telecomdigital.tdstock.activity.groups.monitor.util.SaveBookMarkAsyncTask;
import cc.telecomdigital.tdstock.model.ForeignExchangeInfo;

import com.lightstreamer.ls_client.UpdateInfo;

public class ForeignExchangeActivity extends ChangePortraitAndLandscapeActivity
	implements RefreshHandlerInterface, ILS_UserClient_Response
{
	public final static String					TAG						= ForeignExchangeActivity.class
																			.getSimpleName();
	private final static int[]					IDS_TAB_PANEL				= {
			R.id.fx_dollar_tab, R.id.fx_crossrate_tab, R.id.fx_hkdollar_tab		};
	private final static String[]					TAGS						= {
			"fx_name", "fx_bid", "fx_ask", "fx_high", "fx_low", "fx_net",
			"fx_netpercentage"											};
	private final static String					TAG_ADD_TO_MONITOR			= "addto_monitor_tag";
	private final static String					TAG_CHART					= "fx_chart";
	//private final static String[] TAGS = {"fx_name", "fx_bid", "fx_ask", "fx_high","fx_low"};
	private final int							CONTAINERS_ID_DOLLAR[]		= {
			R.id.fx_eur, R.id.fx_jpy, R.id.fx_gbp, R.id.fx_aud, R.id.fx_chf,
			R.id.fx_nzd, R.id.fx_cad, R.id.fx_hkd							};
	/*private final int CONTAINERS_ID_CROSSRATE[] = {R.id.fx_eur_gbp, R.id.fx_aud_jpy, R.id.fx_eur_jpy, R.id.fx_eur_chf};*/
	private final int							CONTAINERS_ID_CROSSRATE[]	= {
			R.id.fx_eur_gbp, R.id.fx_eur_chf, R.id.fx_gbp_jpy,
			R.id.fx_aud_jpy, R.id.fx_eur_jpy, R.id.fx_chf_jpy				};
	private final int							CONTAINERS_ID_HKDOLLAR[]		= {
			R.id.fx_hkd_eur, R.id.fx_hkd_jpy, R.id.fx_hkd_gbp,
			R.id.fx_hkd_aud, R.id.fx_hkd_chf, R.id.fx_hkd_nzd,
			R.id.fx_hkd_cad											};
	private final static HashMap<String, Integer>	ITEMS_ON_DOLLAR			= new HashMap<String, Integer>();
	static
	{
		ITEMS_ON_DOLLAR.put("EUR", 0);
		ITEMS_ON_DOLLAR.put("JPY", 1);
		ITEMS_ON_DOLLAR.put("GBP", 2);
		ITEMS_ON_DOLLAR.put("AUD", 3);
		ITEMS_ON_DOLLAR.put("CHF", 4);
		ITEMS_ON_DOLLAR.put("NZD", 5);
		ITEMS_ON_DOLLAR.put("CAD", 6);
		ITEMS_ON_DOLLAR.put("HKD", 7);
	}

	private final static HashMap<String, Integer>	ITEMS_ON_CROSSRATE			= new HashMap<String, Integer>();
	static
	{
		ITEMS_ON_CROSSRATE.put("EURGBP", 0);
		ITEMS_ON_CROSSRATE.put("EURCHF", 1);
		ITEMS_ON_CROSSRATE.put("GBPJPY", 2);
		ITEMS_ON_CROSSRATE.put("AUDJPY", 3);
		ITEMS_ON_CROSSRATE.put("EURJPY", 4);
		ITEMS_ON_CROSSRATE.put("CHFJPY", 5);

	}

	private final static HashMap<String, Integer>	ITEMS_ON_HKDOLLAR			= new HashMap<String, Integer>();
	static
	{
		ITEMS_ON_HKDOLLAR.put("EURHKD", 0);
		ITEMS_ON_HKDOLLAR.put("JPYHKD", 1);
		ITEMS_ON_HKDOLLAR.put("GBPHKD", 2);
		ITEMS_ON_HKDOLLAR.put("AUDHKD", 3);
		ITEMS_ON_HKDOLLAR.put("CHFHKD", 4);
		ITEMS_ON_HKDOLLAR.put("NZDHKD", 5);
		ITEMS_ON_HKDOLLAR.put("CADHKD", 6);

	}

	public final static HashMap<String, String>		CODE_TO_NAME				= new HashMap<String, String>();
	static
	{
		/*	CODE_TO_NAME.put(SUBSCRIBE_ITEMS_DOLLAR[0], "歐元/美元");
			CODE_TO_NAME.put(SUBSCRIBE_ITEMS_DOLLAR[1], "美元/日圓");
			CODE_TO_NAME.put(SUBSCRIBE_ITEMS_DOLLAR[2], "英鎊/美元");
			CODE_TO_NAME.put(SUBSCRIBE_ITEMS_DOLLAR[3], "美元/瑞郎");
			CODE_TO_NAME.put(SUBSCRIBE_ITEMS_DOLLAR[4], "澳元/美元");
			CODE_TO_NAME.put(SUBSCRIBE_ITEMS_DOLLAR[5], "紐元/美元");
			CODE_TO_NAME.put(SUBSCRIBE_ITEMS_DOLLAR[6], "美元/加元");
			CODE_TO_NAME.put(SUBSCRIBE_ITEMS_DOLLAR[7], "美元/澳元");*/

		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_DOLLAR[0], "歐元");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_DOLLAR[1], "日圓");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_DOLLAR[2], "英鎊");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_DOLLAR[3], "澳元");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_DOLLAR[4], "瑞郎");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_DOLLAR[5], "紐元");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_DOLLAR[6], "加元");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_DOLLAR[7], "港元");

		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_CROSSRATE[0],
				"歐元/英鎊");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_CROSSRATE[1],
				"歐元/瑞郎");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_CROSSRATE[2],
				"英鎊/日圓");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_CROSSRATE[3],
				"澳元/日圓");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_CROSSRATE[4],
				"歐元/日圓");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_CROSSRATE[5],
				"瑞郎/日圓");

		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_HKDOLLAR[0],
				"歐元");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_HKDOLLAR[1],
				"日圓");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_HKDOLLAR[2],
				"英鎊");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_HKDOLLAR[3],
				"澳元");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_HKDOLLAR[4],
				"瑞郎");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_HKDOLLAR[5],
				"紐元");
		CODE_TO_NAME.put(ForeignExchangeInfo.SUBSCRIBE_ITEMS_HKDOLLAR[6],
				"加元");

	}

	//private boolean							_isSubscribed				= false;
	private final HashMap<String, Integer>			ITEM_TO_TABINDEX			= new HashMap<String, Integer>();
	//private final static HashMap<String, Button> ITEM_TO_LOCATION = new HashMap<String, Button>();

	/*	private final TextView[][]  _textViewOnDollar= new TextView[8][7];
		private final TextView[][]  _textViewOnCrossRate= new TextView[6][7];
		private final TextView[][]  _textViewOnCrosshkDollar= new TextView[7][7];
		*/

	private final TextView[][]					_textViewOnDollar			= new TextView[8][6];
	private final TextView[][]					_textViewOnCrossRate		= new TextView[6][6];
	private final TextView[][]					_textViewOnCrosshkDollar		= new TextView[7][6];

	private final String[]						FIELDS_ON_FOREIGNEXCHANGE	= {
			/*ForeignExchangeInfo.FXREMARK,*/ForeignExchangeInfo.FXBID,
			ForeignExchangeInfo.FXASK, ForeignExchangeInfo.FXHIGH,
			ForeignExchangeInfo.FXLOW, ForeignExchangeInfo.FXNET,
			ForeignExchangeInfo.FXNET_PERCENTAGE							};

	private static final int[]					TAB_BTN_IDS				= {
			R.id.foreign_exchange_tab_btn_dollar,
			R.id.foreign_exchange_tab_btn_crossrate,
			R.id.foreign_exchange_tab_btn_hkdollar							};
	private Button[]							_tabBtns					= new Button[5];
	private RadioButton[]						_tabButtons				= new RadioButton[3];
	private Button								_toolbutton_options;

	private TextView							_top_bar_title;

	private ImageView							_chartImg					= null;
	private final static int						TAG_KEY_FOR_CHARTIMG_CLICK	= R.id.fx_dollar_tab;

	// private static StreamerTimeoutHandler _streamerTimeoutHandler;
	private Context							_context;

	private LightStreamerHandlerOnFX				_lightStreamerHandlerOnFX01	= null;
	private LightStreamerHandlerOnFX				_lightStreamerHandlerOnFX02	= null;
	private LightStreamerHandlerOnFX				_lightStreamerHandlerOnFX03	= null;

	private int								_currentTabIndex			= 0;
	private ViewFlipper							flipper;

	private final boolean						usingBlinkColumn			= true;
	private final int							blinkTime					= 300;						//millisecond

	private static String						IDENTIFIER_0				= ForeignExchangeActivity.class
																			.getSimpleName()
																			+ "00";
	private static String						IDENTIFIER_1				= ForeignExchangeActivity.class
																			.getSimpleName()
																			+ "01";
	private static String						IDENTIFIER_2				= ForeignExchangeActivity.class
																			.getSimpleName()
																			+ "02";

	private final int							INFO_CONTENT_UPDATE			= 1;
	private Handler							UIUpdater					= new Handler()
																	{
																		@Override
																		public void handleMessage(
																				Message msg)
																		{
																			switch (msg.what)
																			{
																				case INFO_CONTENT_UPDATE:
																					if (msg.arg1 < 0)
																						FXInfoUpdate(
																								msg.obj,
																								false);
																					else
																						FXInfoUpdate(
																								msg.obj,
																								true);
																					break;
																			}
																		}
																	};

	private final Object						lockObject				= new Object();

	private void FXInfoUpdate(Object iHandlerObj, boolean iBlink)
	{
		synchronized (lockObject)
		{
			if (!(iHandlerObj instanceof DoThingsReturn))
				return;

			TextView textViewObj;
			DoThingsReturn object = (DoThingsReturn) iHandlerObj;

			textViewObj = (TextView) object.data;
			if (textViewObj == null)
				return;

			textViewObj.setText(object.cmd.toString());
			if (iBlink)
			{
				final ViewGroup parent;

				//This is not a good way of the getting the holder.  Our design needs to be more rigid;
				parent = (ViewGroup) textViewObj.getParent().getParent()
						.getParent().getParent();
				if ((parent != null) && (parent.isShown()))
				{
					Animation animatAction = AnimationUtils.loadAnimation(
							_context, R.anim.just_delay);
					animatAction.setDuration(blinkTime);
					animatAction
							.setAnimationListener(new AnimationListener()
							{
								@Override
								public void onAnimationEnd(
										Animation animation)
								{
									//parent.setBackgroundColor(_context.getResources().getColor(android.R.color.transparent));
									parent.setBackgroundResource(R.drawable.backgound_states_4_index_and_fx);
								}

								@Override
								public void onAnimationRepeat(
										Animation animation)
								{
								}

								@Override
								public void onAnimationStart(
										Animation animation)
								{
								}
							});
					parent.setBackgroundColor(_context.getResources()
							.getColor(R.color.blue));
					parent.setAnimation(animatAction);
					animatAction.startNow();
					parent.invalidate();
					//parent.startAnimation(animatAction);
				}
			}
		}
	}

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		TDStockLog.d(TAG, "created");
		_context = this;
		this.setContentView(R.layout.foreign_exchange);
		/*_streamerTimeoutHandler = new StreamerTimeoutHandler(this,
				_messageHandler);*/

		flipper = (ViewFlipper) findViewById(R.id.foreign_exchange_optionFlipper);

		resetMinHeightOnWorkCenter();
		/*
		          _toolbutton_options = (ImageView)findViewById(R.id.toolbutton_options);
				_toolbutton_options.setFocusable(true);
				_toolbutton_options.setClickable(true);
				_toolbutton_options.setOnClickListener(new DefaultClickHandler(this));
		*/
		_top_bar_title = (TextView) findViewById(R.id.top_bar_title);
		_toolbutton_options = (Button) findViewById(R.id.options_btn);
		//_toolbutton_options.setOnClickListener(new DefaultClickHandler(this));
		_toolbutton_options.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				TDStockLog.d(TAG,
						"close current activity and forwarding to the previous");

				Intent intent = new Intent(getApplicationContext(),
						ForeignExchangeRateOptionsListActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

				SwitchForwardActivity(
						ForeignExchangeRateOptionsListActivity.class,
						intent);

			}
		});

		initAllTextViewsOnFX(CONTAINERS_ID_DOLLAR, _textViewOnDollar,
				ForeignExchangeInfo.SUBSCRIBE_ITEMS_DOLLAR, 0);
		initAllTextViewsOnFX(CONTAINERS_ID_CROSSRATE, _textViewOnCrossRate,
				ForeignExchangeInfo.SUBSCRIBE_ITEMS_CROSSRATE, 1);
		initAllTextViewsOnFX(CONTAINERS_ID_HKDOLLAR,
				_textViewOnCrosshkDollar,
				ForeignExchangeInfo.SUBSCRIBE_ITEMS_HKDOLLAR, 2);
		// connectLightStreamer();
		resetTitle();

		_tabButtons[0] = ((RadioButton) findViewById(R.id.foreign_exchange_optbtn_dollar));
		_tabButtons[1] = ((RadioButton) findViewById(R.id.foreign_exchange_optbtn_crossrate));
		_tabButtons[2] = ((RadioButton) findViewById(R.id.foreign_exchange_optbtn_hkdollar));
		for (int i = 0; i < _tabButtons.length; i++)
		{
			_tabButtons[i].setOnClickListener(viewRadioOptionClick);
		}
		_tabButtons[0].setChecked(true);
		FlipToDesitinateView(0);
	}

	private OnClickListener	viewRadioOptionClick	= new OnClickListener()
											{
												@Override
												public void onClick(
														View iView)
												{
													int objId;

													objId = iView
															.getId();
													switch (objId)
													{
														case R.id.foreign_exchange_optbtn_dollar:
															FlipToDesitinateView(0);
															_currentTabIndex = 0;
															break;
														case R.id.foreign_exchange_optbtn_crossrate:
															FlipToDesitinateView(1);
															_currentTabIndex = 1;
															break;
														case R.id.foreign_exchange_optbtn_hkdollar:
															FlipToDesitinateView(2);
															_currentTabIndex = 2;
															break;
														default:
															_currentTabIndex = -1;
															break;
													}

													//Handle LightStream with the view
													/*	if (_isShowingStreamerTimeoutLabel)
														{
															TDStockLog
																	.d(
																			TAG,
																			"ready to deal with streamer timeout label!");
															performClickStreamerTimeoutLabel();
															if (_streamerTimeoutHandler != null)
															{
																_streamerTimeoutHandler
																		.startCounter(0,0);
															}
														}
														else
														{
															TDStockLog
																	.d(
																			TAG,
																			"there 's no any streamerTimeout label!!");
															reConnectLightstreamerIfDisconnect();
														}*/

													if (_isShowingStreamerTimeoutLabel)
													{
														performClickStreamerTimeoutLabel();
													}

												}
											};

	/**
	 * 
	 * call back handler on lightstreamer
	 *
	 */
	private class LightStreamerHandlerOnFX implements
		LightStreamerHandlerInterface
	{
		HashMap<String, Integer>	itemNameToPos;
		TextView[][]			childrenViewHolder;
		//This is the view Id it belongs to on Flipper
		final int				viewId;

		LightStreamerHandlerOnFX(HashMap<String, Integer> itemNameToPos,
				TextView[][] childrenViewHolder, int iViewID)
		{
			this.itemNameToPos = itemNameToPos;
			this.childrenViewHolder = childrenViewHolder;
			this.viewId = iViewID;
		}

		//Check whether the view is currently visible, so we only perform the effect on the one that is
		//being shown, this is a non UI thread
		public void onUpdate(final int itemPos, final String itemName,
				final UpdateInfo update)
		{
			if (_isInBackground)
				return;

			final Runnable myUpdateResults = new Runnable()
			{
				public void run()
				{
					try
					{
						for (int index = 0; index < FIELDS_ON_FOREIGNEXCHANGE.length; index++)
						{
							String fieldName = FIELDS_ON_FOREIGNEXCHANGE[index];
							String fieldValue = update
									.getNewValue(fieldName);

							if (fieldValue == null)
								fieldValue = CommonDefn.DEFAULT_FIELD_VALUE;

							TextView view = null;
							int line = itemNameToPos.get(itemName);
							int col = index;
							if (line < childrenViewHolder.length
									&& col < childrenViewHolder[0].length)
							{
								view = childrenViewHolder[line][col];
								if (index == 4 || index == 5)
								{
									view.setTextColor(fieldValue
											.indexOf("-") >= 0 ? Color.RED
											: Color.GREEN);
									if (index == 5)
									{
										fieldValue = fieldValue + "%";
									}
								}

								if (index != 0 && index != 1)
								{ //there's another thread to update its value
									view.setText(fieldValue);
									// modified by haibo, 2011-06-20, no need to do so and it cause the anr. 	                                              view.postInvalidate();
								}
							}

							//Update on the page View
							if (index == 0 || index == 1)
							{
								final int itemIndex = index;
								final TextView currentView = view;
								final String field_value = fieldValue;

								if (viewId == flipper
										.getDisplayedChild())
								{
									if (usingBlinkColumn)
									{
										Message updateMessage = /*new Message();*/UIUpdater
												.obtainMessage();

										updateMessage.what = INFO_CONTENT_UPDATE;
										updateMessage.obj = new DoThingsReturn(
												field_value,
												currentView,
												itemIndex == 0 ? Color.RED
														: Color.BLUE);
										updateMessage.arg1 = 1;
										UIUpdater.sendMessage(updateMessage);
									}
									else
									{
										new Thread()
										{
											public void run()
											{
												DoThingsReturn updateWrapper = new DoThingsReturn(
														field_value,
														currentView,
														itemIndex == 0 ? Color.RED
																: Color.BLUE);
												ColorRefreshTask refresh = new ColorRefreshTask(
														ForeignExchangeActivity.this,
														itemIndex == 0 ? Color.RED
																: Color.BLUE,
														updateWrapper);
												if (_messageHandler != null)
													_messageHandler
															.postDelayed(
																	refresh,
																	50);
											}
										}.start();
									}
								}
								else
								{
									Message updateMessage = /*new Message();*/UIUpdater
											.obtainMessage();

									updateMessage.what = INFO_CONTENT_UPDATE;
									updateMessage.obj = new DoThingsReturn(
											field_value,
											currentView,
											itemIndex == 0 ? Color.RED
													: Color.BLUE);
									updateMessage.arg1 = -1;
									UIUpdater.sendMessage(updateMessage);
								}
							}
							//ColorRefreshTask refresh = new ColorRefreshTask(ForeignExchangeActivity.this,0xffffb554,id);
							//_handler.postDelayed(refresh, 50);  
						}
					}
					catch (Exception e)
					{
						TDStockLog.d(
								TAG,
								e.getMessage() == null ? "unknow exception happened!"
										: e.getMessage());
						return;
					}
				}
			};

			new Thread()
			{
				public void run()
				{
					if (_messageHandler != null)
						_messageHandler.post(myUpdateResults);
				}
			}.start();
		}
	}

	private void initAllTextViewsOnFX(int[] contains_id,
			TextView[][] childrenView, final String[] items, int tabIndex)
	{
		//	           final ViewGroup tab = (ViewGroup)findViewById(R.id.mock_tab);
		//	           final Button tabButton = (Button)tab.getChildAt(tabIndex);			
		//		final Button tabButton = _tabBtns[tabIndex];

		for (int index = 0, count = contains_id.length; index < count; index++)
		{
			ViewGroup container = (ViewGroup) findViewById(contains_id[index]);
			if (container != null)
			{
				Button addToMonitor = (Button) container
						.findViewWithTag(TAG_ADD_TO_MONITOR);
				ViewGroup addToMonitor_container = (ViewGroup) container
						.findViewWithTag("addto_monitor_tag_container");
				if (addToMonitor != null)
				{
					AddFxClickHandler addFx = new AddFxClickHandler(
							ForeignExchangeActivity.this);
					addFx.setAdapter(ForeignExchangeInfo.ADAPTER);
					addFx.setItem(items[index]);
					ITEM_TO_TABINDEX.put(items[index], tabIndex);
					//ITEM_TO_LOCATION.put(items[index], addToMonitor);
					addFx.setFields(ForeignExchangeInfo.FXREMARK,
							ForeignExchangeInfo.FXPREV,
							ForeignExchangeInfo.FXNET,
							ForeignExchangeInfo.FXNET_PERCENTAGE);
					addToMonitor.setOnClickListener(addFx);
					addToMonitor_container.setOnClickListener(addFx);
				}

				ImageView imageView = (ImageView) container
						.findViewWithTag(TAG_CHART);
				if (imageView != null)
				{
					imageView.setVisibility(tabIndex == 0 ? View.VISIBLE
							: View.INVISIBLE);
					imageView.setClickable(true);
					imageView.setFocusable(true);

					if (tabIndex == 0)
					{
						TDStockLog.d(TAG, "init tabIndex=" + tabIndex);
						imageView.setTag(TAG_KEY_FOR_CHARTIMG_CLICK,
								new ForwardToChart(items[index]));

						// --------modified by haibo, 2011-07-28, avoid to click
						// the image to enter chart-----------
						// add description too see chart
						rotateToseeChart(container);
						// add description too see chart
					}
					ImageView imageView2 = (ImageView) (container
							.findViewWithTag(TAG_CHART));
					if ((imageView2 != null)
							&& (imageView2.getVisibility() != View.VISIBLE))
					{
						container.setBackgroundResource(R.drawable.backgound_states_4_no_chart);
						_chartImg = imageView2;
					}
					// add description too see chart

				}

				for (int item = 0, itemCount = TAGS.length; item < itemCount; item++)
				{
					if (item == 0)
					{
						TextView fx_name = (TextView) container
								.findViewWithTag(TAGS[item]);
						fx_name.setText(CODE_TO_NAME.get(items[index]));
						continue;
					}
					childrenView[index][item - 1] = (TextView) container
							.findViewWithTag(TAGS[item]);
				}
			}
		}
	}

	@Override
	public void updateBackground(Object handlerId, int color)
	{
		if (!(handlerId instanceof DoThingsReturn))
		{
			return; // invalid parameter
		}
		else
		{
			TextView current = (TextView) (((DoThingsReturn) handlerId).data);
			if (current.getVisibility() != View.VISIBLE)
			{
				return; // no need to update for the view
			}
			if (color <= 0)
			{
				current.setBackgroundColor(((DoThingsReturn) handlerId).errCode);
				current.setText(((DoThingsReturn) handlerId).cmd.toString());
			}
			else
			{
				current.setBackgroundColor(color);
			}
			// modified by haibo, 2011-06-20, no need to do so and it cause the
			// anr. current.postInvalidate();
		}

	}

	@Override
	public Handler getHandler()
	{
		if (((ITDLApplication) getApplicationContext()).isExitApp())
		{
			return null;
		}
		return _messageHandler == null ? new Handler() : _messageHandler;
	}

	private class ForwardToChart implements OnClickListener
	{
		private String	_itemCode;

		public ForwardToChart(String itemCode)
		{
			_itemCode = itemCode;
		}

		@Override
		public void onClick(View v)
		{
			TDStockLog.d(TAG, "onclick itemCode=" + _itemCode);
			forwardToNvChart(_itemCode);
		}

	}

	private void subscriteFX()
	{
		try
		{

			/*
			 * _myClient = ((ITDLApplication) getApplicationContext())
			 * .getLightStreamerClient(); _subscrRefs.clear();
			 */

			if (_lightStreamerHandlerOnFX01 == null)
			{
				_lightStreamerHandlerOnFX01 = new LightStreamerHandlerOnFX(
						ITEMS_ON_DOLLAR, _textViewOnDollar, 0);
			}

			if (_lightStreamerHandlerOnFX02 == null)
			{
				_lightStreamerHandlerOnFX02 = new LightStreamerHandlerOnFX(
						ITEMS_ON_CROSSRATE, _textViewOnCrossRate, 1);
			}

			if (_lightStreamerHandlerOnFX03 == null)
			{
				_lightStreamerHandlerOnFX03 = new LightStreamerHandlerOnFX(
						ITEMS_ON_HKDOLLAR, _textViewOnCrosshkDollar, 2);
			}

			// Thread.yield();
			/*
			 * _subscrRefs.addAll(Arrays.asList(subscribeMultiple(_myClient,
			 * ForeignExchangeInfo.SUBSCRIBE_ITEMS_DOLLAR,
			 * FIELDS_ON_FOREIGNEXCHANGE, ForeignExchangeInfo.ADAPTER,
			 * _lightStreamerHandlerOnFX01)));
			 */

			List<String> iIdList = new ArrayList<String>();
			List<LS_SubscriptionItem> iItemList = new ArrayList<LS_SubscriptionItem>();
			List<ILS_UserClient_Response> iResponseList = new ArrayList<ILS_UserClient_Response>();

			{
				LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
						ForeignExchangeInfo.ADAPTER);
				for (String item : ForeignExchangeInfo.SUBSCRIBE_ITEMS_DOLLAR)
					interestItem.AddSubscribeItem(item);
				for (String field : FIELDS_ON_FOREIGNEXCHANGE)
					interestItem.AddSubscribeSchema(field);

				/*
				 * IDENTIFIER_0 = LSGetUniqueID(); if
				 * (LightStreamerSubscribeItem(IDENTIFIER_0, interestItem,this))
				 * {
				 * 
				 * }
				 */

				iIdList.add(IDENTIFIER_0);
				iItemList.add(interestItem);
				iResponseList.add(this);

			}

			// Thread.yield();
			/*
			 * _subscrRefs.addAll(Arrays.asList(subscribeMultiple(_myClient,
			 * ForeignExchangeInfo.SUBSCRIBE_ITEMS_CROSSRATE,
			 * FIELDS_ON_FOREIGNEXCHANGE, ForeignExchangeInfo.ADAPTER,
			 * _lightStreamerHandlerOnFX02)));
			 */

			{
				// Thread.yield();
				LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
						ForeignExchangeInfo.ADAPTER);
				for (String item : ForeignExchangeInfo.SUBSCRIBE_ITEMS_CROSSRATE)
					interestItem.AddSubscribeItem(item);
				for (String field : FIELDS_ON_FOREIGNEXCHANGE)
					interestItem.AddSubscribeSchema(field);

				/*
				 * IDENTIFIER_1 = LSGetUniqueID(); if
				 * (LightStreamerSubscribeItem(IDENTIFIER_1, interestItem,this))
				 * {
				 * 
				 * }
				 */

				iIdList.add(IDENTIFIER_1);
				iItemList.add(interestItem);
				iResponseList.add(this);

			}

			/*
			 * _subscrRefs.addAll(Arrays.asList(subscribeMultiple(_myClient,
			 * ForeignExchangeInfo.SUBSCRIBE_ITEMS_HKDOLLAR,
			 * FIELDS_ON_FOREIGNEXCHANGE, ForeignExchangeInfo.ADAPTER,
			 * _lightStreamerHandlerOnFX03)));
			 */

			{
				// Thread.yield();
				LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
						ForeignExchangeInfo.ADAPTER);
				for (String item : ForeignExchangeInfo.SUBSCRIBE_ITEMS_HKDOLLAR)
					interestItem.AddSubscribeItem(item);
				for (String field : FIELDS_ON_FOREIGNEXCHANGE)
					interestItem.AddSubscribeSchema(field);

				/*
				 * IDENTIFIER_2 = LSGetUniqueID(); if
				 * (LightStreamerSubscribeItem(IDENTIFIER_2, interestItem,this))
				 * {
				 * 
				 * }
				 */
				iIdList.add(IDENTIFIER_2);
				iItemList.add(interestItem);
				iResponseList.add(this);
			}

			LightStreamerSubscribeItemsInBatch(iIdList, iItemList,
					iResponseList);

			// _isSubscribed = true;
			TDStockLog.d(TAG, "added  Items!");
		}

		catch (Exception e)
		{
			handleLightStreamerException(e);
			TDStockLog.d(
					TAG,
					"other exception!"
							+ (e.getMessage() == null ? "unkonwn Exception!"
									: e.getMessage()));
		}
	}

	public void onConnectionEstablished()
	{
		subscriteFX();
	}

	// @Override
	// public void onConfigurationChanged(Configuration newConfig)
	// {
	// // TODO Auto-generated method stub
	// /* super.onConfigurationChanged(newConfig);
	// resetTabBtnWidth();*/
	// TDStockLog.d(TAG, " ready to enter chart!");
	// // resetTabBtnWidth();
	// /* if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE) {
	// if(_chartImg != null) {
	// _chartImg.performClick();
	// }
	// else {
	// TDStockLog.d(TAG, " chartImg is null");
	// }
	//
	//
	//
	// }
	//
	// */
	//
	// forwardToChartActivity();
	// super.onConfigurationChanged(newConfig);
	//
	// }

	private void initTabButtons()
	{
		// final ViewGroup tab = (ViewGroup)findViewById(R.id.mock_tab);
		for (int index = 0, count = TAB_BTN_IDS.length; index < count; index++)
		{
			_tabBtns[index] = (Button) findViewById(TAB_BTN_IDS[index]);
		}
		for (int index = 0, count = /* tab.getChildCount(); */TAB_BTN_IDS.length; index < count; index++)
		{
			final Button btn = /* (Button)tab.getChildAt(index); */_tabBtns[index];
			final int currentIndex = index;
			final int btnCount = count;
			if (_display != null)
			{
				btn.setWidth((_display.getWidth() - count - 1) / count);
			}

			btn.setOnClickListener(new OnClickListener()
			{
				@Override
				public void onClick(View v)
				{
					final Runnable myUpdateResults = new Runnable()
					{
						public void run()
						{
							for (int item = 0, itemCount = /*
															 * tab.getChildCount(
															 * );
															 */TAB_BTN_IDS.length; item < itemCount; item++)
							{
								Button tmpBtn = /* (Button)tab.getChildAt(item); */_tabBtns[item];
								if (item != 0 && item != itemCount - 1)
								{
									tmpBtn.setBackgroundDrawable(null);
									tmpBtn.setBackgroundColor(0xfff1f1f1);
								}
								else
								{
									tmpBtn.setBackgroundDrawable(null);
									tmpBtn.setBackgroundResource(item == 0 ? R.drawable.rect_left_grey
											: R.drawable.rect_right_grey);
								}
								tmpBtn.setTextColor(0xffcecece);
								// modified by haibo, 2011-06-20, no need to do
								// so and it cause the anr.
								// tmpBtn.postInvalidate();

								ViewGroup tmpView = (ViewGroup) findViewById(IDS_TAB_PANEL[item]);
								tmpView.setVisibility(View.GONE);
								// modified by haibo, 2011-06-20, no need to do
								// so and it cause the anr.
								// tmpView.postInvalidate();

							}
							// btn.setBackgroundColor(0xff97e4e8);
							btn.setBackgroundResource(currentIndex == 0 ? R.drawable.gradient_rect_left
									: (currentIndex == btnCount - 1 ? R.drawable.gradient_rect_right
											: R.drawable.gradient_rect));
							btn.setTextColor(Color.WHITE);
							// modified by haibo, 2011-06-20, no need to do so
							// and it cause the anr. btn.postInvalidate();
							_currentTabIndex = currentIndex;
							TDStockLog.d(TAG, "currentTab index:"
									+ _currentTabIndex);
							ViewGroup tmpView = (ViewGroup) findViewById(IDS_TAB_PANEL[currentIndex]);
							tmpView.setVisibility(View.VISIBLE);
							// modified by haibo, 2011-06-20, no need to do so
							// and it cause the anr. tmpView.postInvalidate();

							/*
							 * if (_isShowingStreamerTimeoutLabel) { TDStockLog
							 * .d(TAG,
							 * "ready to deal with streamer timeout label!");
							 * performClickStreamerTimeoutLabel(); if
							 * (_streamerTimeoutHandler != null) {
							 * _streamerTimeoutHandler .startCounter(0,0); } }
							 * else { TDStockLog .d(TAG,
							 * "there 's no any streamerTimeout label!!");
							 * reConnectLightstreamerIfDisconnect(); }
							 */

							if (_isShowingStreamerTimeoutLabel)
							{
								performClickStreamerTimeoutLabel();
							}

						}
					};

					new Thread()
					{
						public void run()
						{
							if (_messageHandler != null)
								_messageHandler.post(myUpdateResults);
						}
					}.start();
				}
			});
		}

	}

	public void resetTabBtnWidth()
	{
		/*
		 * final ViewGroup tab = (ViewGroup)findViewById(R.id.mock_tab); for(int
		 * index = 0, count = tab.getChildCount(); index < count; index++) {
		 * final Button btn = (Button)tab.getChildAt(index);
		 * btn.setWidth(_display.getWidth() /count); }
		 */

		for (int index = 0, count = TAB_BTN_IDS.length; index < count; index++)
		{
			_tabBtns[index] = (Button) findViewById(TAB_BTN_IDS[index]);
			if (_display != null)
			{
				_tabBtns[index].setWidth((_display.getWidth() - count - 1)
						/ count);
			}

		}

	}

	private void FlipToDesitinateView(int iNewId)
	{
		int curViewId;

		curViewId = flipper.getDisplayedChild();
		if (curViewId == iNewId)
			return;

		flipper.setDisplayedChild(iNewId);

		int tmpId;
		ScrollView scrollObj;

		tmpId = -1;
		if (iNewId == 0)
			tmpId = R.id.foreign_exchange_Scroll01;
		else if (iNewId == 1)
			tmpId = R.id.foreign_exchange_Scroll02;
		else if (iNewId == 2)
			tmpId = R.id.foreign_exchange_Scroll03;

		if (tmpId != -1)
		{
			scrollObj = (ScrollView) findViewById(tmpId);
			if (scrollObj != null)
				scrollObj.scrollTo(0, 0);
		}
	}

	@Override
	protected void onResume()
	{
		super.onResume();
		TDStockLog.d(TAG, "OnResume executed!");
		_currentTabIndex = 0;
		{
			final Runnable myUpdateResults = new Runnable()
			{
				public void run()
				{
					scrollToItemView();
				}
			};

			new Thread()
			{
				public void run()
				{
					if (_messageHandler != null)
						_messageHandler.post(myUpdateResults);
				}
			}.start();
		}

		/*
		 * if(_isFirstLink || _isExceptionHappend) { final Runnable
		 * myUpdateResults = new Runnable() { public void run() {
		 * connectLightStreamer(); } };
		 * 
		 * new Thread() { public void run() {
		 * _messageHandler.post(myUpdateResults); } }.start();
		 * 
		 * }
		 */

		/*
		 * if (_streamerTimeoutHandler != null) {
		 * _streamerTimeoutHandler.startCounter(0,0); }
		 */

		/*
		 * if (!((ITDLApplication)
		 * getApplicationContext()).isLightStreamerConnected()) {
		 * TDStockLog.d(TAG, "OnResume: reconnect ls");
		 * connectLightStreamerEx(getMyOwnContext()); return; } else {
		 * TDStockLog.d(TAG, "OnResume: restore to the last connection!"); new
		 * SubscriptionTask().execute(); }
		 */

		/*
		 * final Runnable myUpdateResults = new Runnable() { public void run() {
		 * if (((ITDLApplication) getApplicationContext())
		 * .isLightStreamerConnected()) { //onConnectionEstablished(); new
		 * SubscriptionTask().execute(); } else {
		 * connectLightStreamerEx(getMyOwnContext()); } } };
		 * 
		 * new Thread() { public void run() { if (_messageHandler != null)
		 * _messageHandler.post(myUpdateResults); } }.start();
		 */

		/*
		 * if (!_isSubscribed) {
		 * 
		 * new SubscriptionTask().execute();
		 * 
		 * }
		 */
	}

	private class AddFxClickHandler extends DefaultClickHandler
	{
		private String	_item;
		private String	_adapter;
		private String	_fieldName;
		private String	_fieldValue;
		private String	_fieldNet;
		private String	_fieldNetPercentage;

		public AddFxClickHandler(Context context)
		{
			super(context);
		}

		public void setItem(String item)
		{
			_item = item;
		}

		public void setAdapter(String adapter)
		{
			_adapter = adapter;
		}

		public void setFields(String name, String value, String net,
				String netpercentage)
		{
			_fieldName = name;
			_fieldValue = value;
			_fieldNet = net;
			_fieldNetPercentage = netpercentage;
		}

		@Override
		protected void onDefaultAction()
		{

			// 延迟模式
			if (((ITDLApplication) getApplicationContext()).getModeType() == CommonDefn.ModeType.DELARY)
			{
				DBHelper dbHelper = new DBHelper(
						ForeignExchangeActivity.this);
				try
				{
					int customerId = ((ITDLApplication) getApplicationContext())
							.getUserId(-1);

					if (dbHelper.isSubscribeItemExist(customerId, _item,
							_adapter))
					{
						new CustomizeDialog(getMyOwnContext(), "",
								getResources().getString(
										R.string.monitor_exist_index))
								.show();
						/*
						 * new AlertDialog.Builder(
						 * ForeignExchangeActivity.thisgetMyOwnContext())
						 * .setTitle(getResources().getString(R.string.info))
						 * .setMessage
						 * (getResources().getString(R.string.monitor_exist_index
						 * )) .setIcon(getResources().getDrawable(R.drawable.
						 * help_menu_icon))
						 * .setPositiveButton(getResources().getString
						 * (R.string.ok), new
						 * DialogInterface.OnClickListener(){public void
						 * onClick(DialogInterface dialoginterface,int
						 * i){}}).show();
						 */

					}
					else if (dbHelper.isFullWithItemInMonitor(customerId))
					{
						new CustomizeDialog(
								getMyOwnContext(),
								"",
								getResources()
										.getString(
												R.string.monitor_is_full_with_items))
								.show();
						/*
						 * new AlertDialog.Builder(
						 * ForeignExchangeActivity.thisgetMyOwnContext())
						 * .setTitle(getResources().getString(R.string.info))
						 * .setMessage(getResources().getString(R.string.
						 * monitor_is_full_with_items))
						 * .setIcon(getResources().getDrawable
						 * (R.drawable.help_menu_icon))
						 * .setPositiveButton(getResources
						 * ().getString(R.string.ok), new
						 * DialogInterface.OnClickListener() {public void
						 * onClick(DialogInterface dialoginterface,int
						 * i){}}).show();
						 */
					}
					else
					{
						// 向数据库中插入
						long result = dbHelper.insertSubscribeItem(
								customerId, _item, _adapter,
								_fieldName, _fieldValue, _fieldNet,
								_fieldNetPercentage);
						/*
						 * if(result>0) { new
						 * AlertDialog.Builder(ForeignExchangeActivity.this)
						 * .setTitle(getResources().getString(R.string.info))
						 * .setMessage
						 * (getResources().getString(R.string.monitor_add_to))
						 * .setIcon
						 * (getResources().getDrawable(R.drawable.help_menu_icon
						 * ))
						 * .setPositiveButton(getResources().getString(R.string
						 * .ok), new DialogInterface.OnClickListener(){public
						 * void onClick(DialogInterface dialoginterface, int i){
						 * } }).show(); }
						 */
						if (result > 0)
						{
							// startAnim(genBitMapforAnim(_item));
							/* modify by zor(ouyangzhihui) */
							String temp = _item.length() >= 2 ? _item
									.substring(0, 2) : _item;
							startAnimat(temp);
						}
						TDStockLog.d(TAG, "insert result:" + result);
					}
				}
				catch (Exception e)
				{
					// TODO Auto-generated catch block
					e.printStackTrace();
					TDStockLog.d(
							TAG,
							"insert result:" + e.getMessage() == null ? "unknown exception!"
									: e.getMessage());
				}
				finally
				{
					dbHelper.cleanup();
				}
				// 非延迟模式
			}
			else
			{
				new SaveBookMarkAsyncTask(_item,
						CommonDefn.BookMarkType.fx.getBookMarkType(),
						ForeignExchangeActivity.this,
						MonitorUtil.getInstance(),
						_item.length() >= 2 ? _item.substring(0, 2)
								: _item).execute();
			}

		}

	}

	private void scrollToItemView()
	{
		final String itemCode = ((ITDLApplication) getApplicationContext())
				.getString(CommonDefn.FROM_MONITOR_TO_ACTIVITY_FORWARDING_ITEM);
		if (itemCode == null || itemCode.length() < 1)
		{
			return;
		}
		((ITDLApplication) getApplicationContext()).putString(
				CommonDefn.FROM_MONITOR_TO_ACTIVITY_FORWARDING_ITEM, null);

		// to avoid NullPointerException
		// int tabIndex = ITEM_TO_TABINDEX.get(itemCode);
		int tabIndex = ITEM_TO_TABINDEX.containsKey(itemCode) ? ITEM_TO_TABINDEX
				.get(itemCode) : 0;

		final Button tab = _tabButtons[tabIndex];
		if (tab == null)
		{
			return;
		}

		_messageHandler.post(new Runnable()
		{
			public void run()
			{
				tab.performClick();
				/*
				 * View container = findViewById(R.id.scrollview01);
				 * if(container!= null) { Button addToMonitor =
				 * ITEM_TO_LOCATION.get(itemCode); if(addToMonitor != null) {
				 * int index = -1; if(ITEMS_ON_DOLLAR.containsKey(itemCode)) {
				 * index = ITEMS_ON_DOLLAR.get(itemCode); } else
				 * if(ITEMS_ON_CROSSRATE.containsKey(itemCode)) { index =
				 * ITEMS_ON_CROSSRATE.get(itemCode); } else
				 * if(ITEMS_ON_HKDOLLAR.containsKey(itemCode)) { index =
				 * ITEMS_ON_HKDOLLAR.get(itemCode); }
				 * 
				 * //BaseActivity.scrollToBottom(container, index, 120);
				 * BaseActivity.scrollToBottom(container, addToMonitor); }
				 * //((ScrollView)container).scrollBy(0,
				 * addToMonitor.getMeasuredHeight()); }
				 */

			}

		});

	}

	private void forwardToNvChart(final String itemCode)
	{
		if (_currentTabIndex == 0)
		{
			((ITDLApplication) getApplicationContext())
					.setCurrentStockName(ForeignExchangeInfo.CODE_TO_NAME
							.get(itemCode)); // it's the actual name of the
											// foreign exchange;
			TDStockLog.d(
					TAG,
					"itemName="
							+ ForeignExchangeInfo.CODE_TO_NAME
									.get(itemCode));
			Intent intent = new Intent(this, ForexChartActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
					| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
			intent.putExtra(FinalKey.ITEMCODE, itemCode);
			SwitchActivityFromHost(ForexChartActivity.class, intent);
		}
		else
		{
			TDStockLog.d(TAG, "curent tab index:" + _currentTabIndex);
		}
	}

	private void resetTitle()
	{
		if (((ITDLApplication) getApplicationContext()).getDataMode() == CommonDefn.DataMode.Delay)
		{
			_top_bar_title.setText(getResources().getString(
					R.string.foreign_exchange)
					+ "("
					+ getResources().getString(
							R.string.delay_mode_title_tips) + ")");
		}
		else
		{
			_top_bar_title.setText(getResources().getString(
					R.string.foreign_exchange));
		}
		// modified by haibo, 2011-06-20, no need to do so and it cause the anr.
		// _top_bar_title.postInvalidate();

	}

	protected Context getMyOwnContext()
	{
		// return _context;
		return getParent();
	}

	private void rotateToseeChart(ViewGroup container)
	{
		// add description too see chart
		container.setOnFocusChangeListener(new OnFocusChangeListener()
		{

			@Override
			public void onFocusChange(View v, boolean hasFocus)
			{
				TextView rotateToSeeChart = (TextView) (((ViewGroup) v)
						.findViewWithTag("rotate_to_see_chart"));
				ImageView imageView = (ImageView) (((ViewGroup) v)
						.findViewWithTag(TAG_CHART));
				if (rotateToSeeChart != null)
				{
					rotateToSeeChart.setVisibility(hasFocus
							&& (imageView != null)
							&& (imageView.getVisibility() == View.VISIBLE) ? View.VISIBLE
							: View.INVISIBLE);
					// modified by haibo, 2011-06-20, no need to do so and it
					// cause the anr. rotateToSeeChart.postInvalidate();
					/*
					 * if((imageView != null) && (imageView.getVisibility() ==
					 * View.VISIBLE)) {
					 */
					// _chartImg = imageView; //to allow to enter chart activity
					// any time for adapting to the change on screen changes

					/*
					 * } else { _chartImg = null; }
					 */
					_chartImg = imageView;

				}
			}

		});
	}

	private class SubscriptionTask extends AsyncTask<String, Void, Void>
	{

		@Override
		protected Void doInBackground(String... params)
		{
			onConnectionEstablished();
			return null;
		}

		@Override
		protected void onPostExecute(Void result)
		{
			super.onPostExecute(result);
		}

	}

	@Override
	protected void onDestroy()
	{
		// TODO Auto-generated method stub
		super.onDestroy();

		/*
		 * if (_streamerTimeoutHandler != null) {
		 * _streamerTimeoutHandler.killCounter(); _streamerTimeoutHandler =
		 * null; }
		 */
	}

	@Override
	protected void onPause()
	{
		super.onPause();

		/* unSubscribeItems(); */
		/*
		 * if (_streamerTimeoutHandler != null) {
		 * _streamerTimeoutHandler.resetCounter(); }
		 */
	}

	@Override
	protected boolean forwardToChartActivity()
	{
		// TODO Auto-generated method stub

		if (_currentTabIndex == 0)
		{
			if (_chartImg != null)
			{

				// --------modified by haibo, 2011-07-28, avoid to click the
				// image to enter chart-----------
				// _chartImg.performClick();
				OnClickListener clicking = (OnClickListener) _chartImg
						.getTag(TAG_KEY_FOR_CHARTIMG_CLICK);
				if (clicking != null)
				{
					clicking.onClick(_chartImg);
				}
				// --------modified by haibo, 2011-07-28, avoid to click the
				// image to enter chart-----------

			}
			else
			{
				TDStockLog.d(TAG, "_chartImg is null!");

			}

			TDStockLog.d(TAG, "forward to chart");

			return true;
		}
		else
		{

			TDStockLog.d(TAG, " not   forward to chart");

			return false;
		}

		/*
		 * if(_chartImg != null) { _chartImg.performClick(); }
		 */

	}

	private void reConnectLightstreamerIfDisconnect()
	{
		if (!SystemInfo.isNetworkingConnected(this))
		{
			new CustomizeDialog(getMyOwnContext(), getResources().getString(
					R.string.info), getResources().getString(
					R.string.networking_disconnect_tips)).show();
			return;
		}

		if (!appHost.LSClient_IsConnected())
		{
			connectLightStreamerExt(getMyOwnContext());
		}

	}

	@Override
	public ActivityGroupController GetActivityGroupController()
	{
		return ForeignExchangeGroup.GetActivityGroupHostControl();
	}

	@Override
	public void onUpdate(String iIdentifier, int iSchemaIndex,
			String iSchemaValue, UpdateInfo iUpdateInfo)
	{
		super.onUpdate(iIdentifier, iSchemaIndex, iSchemaValue, iUpdateInfo);
		if (IDENTIFIER_0.equals(iIdentifier))
		{
			_lightStreamerHandlerOnFX01.onUpdate(iSchemaIndex, iSchemaValue,
					iUpdateInfo);
		}
		else if (IDENTIFIER_1.equals(iIdentifier))
		{
			_lightStreamerHandlerOnFX02.onUpdate(iSchemaIndex, iSchemaValue,
					iUpdateInfo);
		}
		else if (IDENTIFIER_2.equals(iIdentifier))
		{
			_lightStreamerHandlerOnFX03.onUpdate(iSchemaIndex, iSchemaValue,
					iUpdateInfo);
		}

	}

}
